﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="project.aspx.cs" Inherits="www.pages.project.project" ValidateRequest="false" %>

<%@ Register TagPrefix="webdiyer" Namespace="Wuqi.Webdiyer" Assembly="AspNetPager" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../plugins/layer/theme/default/layer.css" rel="stylesheet" />
    <link href="../../css/lanai-ui.min.css" rel="stylesheet" />
    <link href="../../css/pager.css" rel="stylesheet" />
</head>
<body>
    <section class="content">
        <form id="form1" runat="server">
            <div class="top topbox">
                <div class="box-body pull-right">
                    <div class="btn btn-group">
                        <button id="btnedit" type="button" class="btn btn-success"><i class="fa fa-globe"></i>编辑此项目</button>
                        <button id="btndelete" type="button" class="btn btn-danger"><i class="fa fa-remove"></i>删除此项目</button>
                    </div>
                </div>
            </div>
            <section class="invoice">
                <div class="row">
                    <div class="col-xs-12">
                        <h2 class="page-header">
                            <i class="fa fa-globe"></i>
                            <asp:Label ID="lbPrject" runat="server"></asp:Label>
                            <small class="pull-right">日期:
                                <asp:Label ID="lbDate" runat="server"></asp:Label></small>
                        </h2>
                    </div>
                </div>
                <div class="row invoice-info">
                    <div class="col-xs-12 invoice-col">
                        <p class="text-muted well well-sm no-shadow">
                            <asp:Label ID="lbComment" runat="server"></asp:Label>
                        </p>

                    </div>
                </div>
                <div class="row invoice-info">
                    <div class="col-sm-4 invoice-col">
                        <div class="form-inline pull-left">
                            <span class="lead"><i class="fa fa-file-word-o"></i>文档模板</span>
                        </div>
                        <div class="form-group form-inline pull-right">
                            <div class="input-group">
                                <input type="text" class="form-control" id="txtDocName" placeholder="请输入文档名称" runat="server" />
                                <div class="input-group-btn">
                                    <asp:LinkButton ID="btnSearchDocs" runat="server" CssClass="btn btn-default no-radius no-border-left" OnClick="btnSearchDocs_Click"><i class="fa fa-search"></i></asp:LinkButton>
                                </div>
                                <div class="input-group-btn">
                                    <a id="btnadd" href="#" class="btn btn-default no-radius"><i class="fa fa-plus"></i>新建模板</a>
                                </div>
                            </div>
                        </div>
                        <asp:Repeater ID="list_data" runat="server">
                            <HeaderTemplate>
                                <table class="table table-bordered table-striped table-hover text-center no-margin-bottom list_docs">
                                    <thead>
                                        <tr>
                                            <th style="width: 60px">序号</th>
                                            <th style="width: 120px; text-align: left">文档名称</th>
                                            <th>描述</th>
                                            <th style="width: 120px">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td><%#Container.ItemIndex+1%></td>
                                    <td style="text-align: left"><%#Eval("doc_name") %></td>
                                    <td><%#Core.Helper.StringUtil.subString(Eval("doc_comment").ToString(),15,true) %></td>
                                    <td>
                                        <div class="btn-group">
                                            <a href="#" class="btn btn-sm btn-default" onclick="edit_doc('<%#Eval("doc_id") %>')">编辑</a><a href="#" class="btn btn-danger btn-sm" onclick="delete_doc('<%#Eval("doc_id") %>')">删除</a>
                                        </div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </tbody>
                                    </table>
                            </FooterTemplate>
                        </asp:Repeater>
                        <%if (list_data.Items.Count <= 0)
                            { %>
                        <table class="table table-bordered table-striped table-hover text-center no-margin-bottom">
                            <thead>
                                <tr>
                                    <th style="width: 60px">序号</th>
                                    <th style="width: 120px; text-align: left">文档名称</th>
                                    <th>描述</th>
                                    <th style="width: 120px">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="4">未查询到文档</td>
                                </tr>
                            </tbody>
                        </table>
                        <%} %>
                        <table class="table_pager table">
                            <tr>
                                <td class="pager_area">
                                    <webdiyer:AspNetPager ID="PagerDoc" runat="server" NumericButtonType="Text" BorderStyle="None" CurrentPageButtonClass="cpb" PageSize="12" CustomInfoSectionWidth="60%" ShowBoxThreshold="5" HorizontalAlign="Right" AlwaysShow="false" OnPageChanging="PagerDoc_PageChanging" PagingButtonSpacing="0px" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页">
                                    </webdiyer:AspNetPager>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-sm-8 invoice-col">
                        <div class="form-inline pull-left">
                            <span class="lead"><i class="fa fa-flag-o"></i>文档标签</span>
                        </div>
                        <div class="form-group form-inline pull-right">
                            <div class="input-group">
                                <input type="text" class="form-control" id="txtTag" placeholder="请输入标签名称" runat="server" />
                                <div class="input-group-btn">
                                    <asp:LinkButton ID="btnSearchTag" runat="server" CssClass="btn btn-default no-radius no-border-left" OnClick="btnSearchTag_Click"><i class="fa fa-search"></i></asp:LinkButton>
                                </div>
                                <div class="input-group-btn">
                                    <a id="btnaddTag" href="#" class="btn btn-default no-radius"><i class="fa fa-plus"></i>新建标签</a>
                                </div>
                            </div>
                        </div>
                        <asp:Repeater ID="list_tags" runat="server">
                            <HeaderTemplate>
                                <table class="table table-bordered table-striped table-hover text-center no-margin-bottom list_tags">
                                    <thead>
                                        <tr>
                                            <th style="width: 60px">序号</th>
                                            <th style="width: 120px">名称</th>
                                            <th style="width: 80px">类型</th>
                                            <th style="width: 200px">描述</th>
                                            <th>关联文档</th>
                                            <th style="width: 120px">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td><%#Container.ItemIndex+1 %></td>
                                    <td style="text-align: left"><%#Eval("tag_name") %></td>
                                    <td><%#Core.Util.getTagStatusName(Eval("tag_type").ToString()) %></td>
                                    <td style="text-align: left"><%#Eval("tag_comment") %></td>
                                    <td style="text-align: left"><%#ShowHtmlDocs(Eval("tag_type").ToString(),Eval("tag_id").ToString(),40) %></td>
                                    <td>
                                        <div class="btn-group">
                                            <a href="#" class="btn btn-sm btn-default" onclick="edit_tag('<%#Eval("tag_id") %>')">编辑</a><a href="#" class="btn btn-danger btn-sm" onclick="delete_tag('<%#Eval("tag_id") %>')">删除</a>
                                        </div>
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </tbody>
                                    </table>
                            </FooterTemplate>
                        </asp:Repeater>
                        <%if (list_tags.Items.Count <= 0)
                            { %>
                        <table class="table table-bordered table-striped table-hover text-center no-margin-bottom">
                            <thead>
                                <tr>
                                    <th style="width: 60px">序号</th>
                                    <th style="width: 120px">名称</th>
                                    <th style="width: 80px">类型</th>
                                    <th style="width: 100px">描述</th>
                                    <th>关联文档</th>
                                    <th style="width: 120px">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="6">未查询到标签</td>
                                </tr>
                            </tbody>
                        </table>
                        <%} %>
                        <table class="table_pager table">
                            <tr>
                                <td class="pager_area">
                                    <webdiyer:AspNetPager ID="PagerTag" runat="server" NumericButtonType="Text" BorderStyle="None" CurrentPageButtonClass="cpb" PageSize="12"
                                        CustomInfoSectionWidth="60%" ShowBoxThreshold="5" HorizontalAlign="Right" AlwaysShow="false" OnPageChanging="PagerTag_PageChanging" PagingButtonSpacing="0px" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页">
                                    </webdiyer:AspNetPager>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </section>

            <input type="hidden" id="hidProject_id" runat="server" value="0" />
        </form>
    </section>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../plugins/layer/layer.js"></script>
    <script src="../../js/lanai-ui.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnedit").click(function () {
                layer.open({
                    type: 2,
                    title: "编辑项目",
                    shadeClose: false,
                    shade: 0.6,
                    maxmin: false,
                    scrollbar: false,
                    area: ["600px", "345px"],
                    content: "/pages/project/new.aspx?project=" + $("#hidProject_id").val()
                });
            });

            $("#btndelete").click(function () {
                var index = layer.confirm('您确定要删除此项目吗？\t\r\n<br/>删除后对应文档和标签均将被删除且无法恢复！', {
                title: '系统提示',
                btn: ['确认删除', '取消']
                }, function () {
                    if ($(".list_docs tbody tr").length > 0) {
                        layer.close(index);
                        layer.alert("该项目下存在文档模板,请先将文档模板删除", { title: '系统提示', icon: 2 });
                        return;
                    }
                    if ($(".list_tags tbody tr").length > 0) {
                        layer.close(index);
                        layer.alert("该项目下存在文档标签,请先将标签删除", { title: '系统提示', icon: 2 });
                        return;
                    }
                    var param = {};
                    param["function_type"] = "delProject";
                    param["project"] = $("#hidProject_id").val();
                    $.post("/api/ProjectHandler.ashx", param, function (res) {
                        var resobj = JSON.parse(res);
                        if (resobj.statusCode == "200") {
                            location.href="/pages/first.aspx";
                        }
                        else {
                            layer.close(index);
                            layer.msg(resobj.msg, { icon: 1 });
                            return;
                        }
                    })
                }, function () {
                    layer.close(index);
                });
            });

            $("#btnadd").click(function () {
                edit_doc("0");
            });

            $("#btnaddTag").click(function () {
                edit_tag("0");
            });
        })

        function doSaveProject(id,name, comment) {
            var param = {};
            param["function_type"] = "addProject";
            param["id"] = id;
            param["name"] = name;
            param["comment"] = comment;
            $.post("/api/ProjectHandler.ashx", param, function (res) {                
                var resobj = JSON.parse(res);
                layer.closeAll();
                location.reload();
            })
        }

        function doSaveDocument(id, name, comment, template) {
            var param = {};
            param["function_type"] = "addDocument";
            param["project"] = $("#hidProject_id").val();
            param["id"] = id;
            param["name"] = name;
            param["comment"] = comment;
            param["template"] = template;
            $.post("/api/DocumentHandler.ashx", param, function (res) {
                var resobj = JSON.parse(res);
                layer.closeAll();
                location.reload();
            });
        }

        function edit_doc(doc_id) {
            var title = "新建模板";
            if (doc_id != "0") {
                title = "编辑文档";
            }
            var index = layer.open({
                type: 2,
                title: title,
                shadeClose: false,
                shade: 0.6,
                maxmin: false,
                area: ["800px", "1000px"],
                content: "../word/word.aspx?project=" + $("#hidProject_id").val() + "&doc=" + doc_id
            });

            layer.full(index);
        }

        function delete_doc(doc_id) {
            var index = layer.confirm('您确定要删除吗？', {
                title: '系统提示',
                btn: ['确认', '取消']
            }, function () {
                var param = {};
                param["function_type"] = "delDocument";
                param["project"] = $("#hidProject_id").val();
                param["id"] = doc_id;
                $.post("/api/DocumentHandler.ashx", param, function (res) {
                    var resobj = JSON.parse(res);
                    if (resobj.statusCode == "200") {
                        location.reload();
                    }
                    else {
                        layer.msg(resobj.msg, { icon: 1 });
                        return;
                    }
                })
            }, function () {
                layer.close(index);
            });
        }

        function edit_tag(tag_id) {
            var title = "新建标签";
            if (tag_id != "0") {
                title = "编辑标签";
            }
            layer.open({
                type: 2,
                title: title,
                shadeClose: false,
                shade: 0.6,
                maxmin: false,
                area: ["600px", "700px"],
                content: "../tag/tag.aspx?project=" + $("#hidProject_id").val() + "&tag=" + tag_id
            });
        }

        function delete_tag(tag_id) {
            var index = layer.confirm('您确定要删除吗？', {
                title: '系统提示',
                btn: ['确认', '取消']
            }, function () {
                var param = {};
                param["function_type"] = "delTag";
                param["project"] = $("#hidProject_id").val();
                param["id"] = tag_id;
                $.post("/api/TagHandler.ashx", param, function (res) {
                    var resobj = JSON.parse(res);
                    if (resobj.statusCode == "200") {
                        location.reload();
                    }
                    else {
                        layer.msg(resobj.msg, { icon: 1 });
                        return;
                    }
                })
            }, function () {
                layer.close(index);
            });
        }
        //保存标签
        function doSaveTag(tagid, tagname, tagcomment, tagtype, tagcontent, docs) {
            var param = {};
            param["function_type"] = "addTag";
            param["project"] = $("#hidProject_id").val();
            param["id"] = tagid;
            param["name"] = tagname;
            param["comment"] = tagcomment;
            param["tag_type"] = tagtype;
            param["content"] = tagcontent;
            param["docs"] = docs;

            $.post("/api/TagHandler.ashx", param, function (res) {
                var resobj = JSON.parse(res);
                layer.closeAll();
                location.reload();
            });
        }
    </script>
</body>
</html>
